package com.romotc.qqrobot.webqq.qqInterfaceCall;

import java.util.ArrayList;

import org.json.JSONException;
import org.json.JSONObject;

import com.romotc.qqrobot.bean.QQLogedin;
import com.romotc.qqrobot.webqq.SysConstant;
import com.romotc.scache.httpreq;
/**
 * 登录成功之后自动滴答 保持在线状态
 * GET http://web.qq.com/web2/get_msg_tip?uin=&tp=1&id=0&retype=1&rc=11&lv=3&t=1328082943448
 * @author Administrator
 *
 */
public class Get_msg_tip_InterCall extends QQInterfaceCall {

	@Override
	public String buildReqBody(JSONObject reqDataObj, QQLogedin loginQQ)
			throws Exception {
		return null;
	}

	@Override
	public int getLogLevel() {
		return 1001;
	}

	@Override
	public String getReqUrl(JSONObject reqDataObj, QQLogedin loginQQ)
			throws JSONException {
		//http://web.qq.com/web2/get_msg_tip?uin=&tp=1&id=0&retype=1&rc=11&lv=3&t=1326943639874
		//http://web.qq.com/web2/get_msg_tip?uin=&tp=1&id=0&retype=1&rc=15&lv=3&t=1326943879866
		return "http://web.qq.com/web2/get_msg_tip?uin=&tp=1&id=0&retype=1&rc=" 
					+ loginQQ.getRc() + "&lv=3&t=" + System.currentTimeMillis();
		//lv 3 在线
		//lv 2 离线  http://web.qq.com/web2/get_msg_tip?uin=&tp=1&id=0&retype=1&rc=24&lv=2&t=1328083723453
	}

	@Override
	public int getReq_method() {
		return httpreq.REQUEST_GET;
	}

	@Override
	public boolean hasPreCall(QQLogedin loginQQ, JSONObject reqDataObj) {
		return false;
	}

	@Override
	public ArrayList<String> myReqHeaders(int reqBodyLen, QQLogedin loginQQ,JSONObject reqDataObj) {
//		ArrayList<String> s = buildReqHeaders(loginQQ,
//				"http://web.qq.com/", 
//				"web.qq.com");
		ArrayList<String> s = new ArrayList<String>();

		s.add("Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
		s.add("Accept-Charset:UTF-8,*;q=0.5");
		s.add("Accept-Encoding:gzip,deflate,sdch");
		s.add("Accept-Language:zh-CN,zh;q=0.8");
		s.add("Cache-Control:max-age=0");
		s.add("Cookie:" + loginQQ.getCookieString());
		s.add("Host:web.qq.com");
		s.add("Proxy-Connection:keep-alive");
		s.add("User-Agent:" + SysConstant.User_Agent);
		return s;
	}

	@Override
	public JSONObject preCall(QQLogedin loginQQ, JSONObject reqDataObj)
			throws Exception {
		return null;
	}
	
	private static Get_msg_tip_InterCall instance;
	public static synchronized Get_msg_tip_InterCall getInstance() {
		if(instance == null)
			instance = new Get_msg_tip_InterCall();
		return instance;
	}

}
